<?php

namespace app\admin\model;


use think\Model;

class Group extends Model {


    // 设置当前模型对应的完整数据表名称
    protected $table = '__AUTH_GROUP__';

    // 自动写入时间戳
    protected $autoWriteTimestamp = true;

    public function __construct($data = []) {
        parent::__construct($data);
    }

    //修改器
    public function getStatusTextAttr($value, $data) {
        return get_status_html($data['status']);
    }

    //自定义方法
    public static function lists($title, $status) {
        $map = array();
        if ($status != null && $status !== '') {
            array_push($map, ['a.status', '=', $status]);
        } else {
            array_push($map, ['a.status', '>=', 0]);
        }

        if ($title !== '' && !empty($title)) {
            array_push($map, ['a.title', 'like', '%' . $title . '%']);
        }
        return self::alias('a')->where($map)->order('a.id desc')->paginate();
    }

    public static function state($id, $status) {
        return self::where('id', $id)->update(['status' => $status]);
    }

    public static function listBiz(){
        $map = array(['id', '>=', 10]);
        return self::alias('a')->where($map)->order('a.id')->select();
    }
}